<script setup lang="ts">
import { ref } from "vue";
import { formRules } from "./utils/rule";
import { FormProps } from "./utils/types";

const props = withDefaults(defineProps<FormProps>(), {
  formInline: () => ({
    id: 0,
    productName: "",
    productCode: "",
    productPrice: 0,
    productSalePrice: 0,
    productNum: 0
  })
});

const ruleFormRef = ref();
const newFormInline = ref(props.formInline);

function getRef() {
  return ruleFormRef.value;
}

defineExpose({ getRef });
</script>

<template>
  <el-form
    ref="ruleFormRef"
    :model="newFormInline"
    :rules="formRules"
    label-width="82px"
  >
    <el-form-item label="商品名称" prop="productName">
      <el-input
        v-model="newFormInline.productName"
        clearable
        placeholder="请输入商品名称"
      />
    </el-form-item>

    <el-form-item label="商品条码" prop="productCode">
      <el-input
        v-model="newFormInline.productCode"
        clearable
        placeholder="请输入商品条码"
      />
    </el-form-item>
    <el-form-item label="商品价格" prop="productPrice">
      <el-input
        v-model="newFormInline.productPrice"
        clearable
        placeholder="请输入商品价格"
      />
    </el-form-item>
    <el-form-item label="商品销售价格" prop="productSalePrice">
      <el-input
        v-model="newFormInline.productSalePrice"
        clearable
        placeholder="请输入商品销售价格"
      />
    </el-form-item>
    <el-form-item label="商品库存" prop="productNum">
      <el-input
        v-model="newFormInline.productNum"
        clearable
        placeholder="请输入商品库存"
      />
    </el-form-item>
  </el-form>
</template>
